<?php
// Header 
$this->left_menu="manage_contact";
$this->set('title_for_layout', __("Danh sách liên hệ ", true));
$params = array(
	'root'	=>	$this->params['named']['root']
);
if (isset($this->params['plugin'])) {
	$params['plugin'] = $this->params['plugin'];
} else {
	$params['plugin'] = null;
}
// Load Css
echo $this->Html->css('/contacts/css/index');
echo $this->Html->css('/contacts/css/dialog');
echo $this->Html->css('/contacts/css/manage_contact');

// Load Javascript

//echo $this->Html->script('/contacts/js/interface');
echo $this->Html->script('/contacts/js/index');
echo $this->Html->script('/contacts/js/btnAction');
?>
<script language="javascript">
$(document).ready(function() {
	$("#contact_info").dialog({
		width: 600,
		resizable : false,
		autoOpen : false,
		modal	:	true
	});

	$('.view_page_link').click(function() {
		$.ajax({
			type: 'GET',
			url: $(this).attr('href'),
			success: function(responseContent) {
				booking_detail = $("#contact_info");
				booking_detail.html(responseContent);
				booking_detail.dialog("open");
			}
		});
		
		return false;
	});
});
</script>
<script language="javascript" type="text/javascript">
$(document).ready(function() {
	$('div.buttons a.cancel').click(function() {
		if (confirm("<?php __("Bạn có thật sự muốn xóa các thông tin liên lạc đã được đánh dấu?")?>")) {
			var checkboxes = $('input:checked.index').clone();       checkboxes.each(function() {$(this).attr('checked', 'checked');});
			$('form#mass_delete').append(checkboxes).submit();
		}
	});
});
</script>
<style>
.alias {
	font-style:italic;
}
.field_name {
	font-weight:bold;
}
</style>


<h2 class='page_heading'><?php __("Thông tin liên hệ ")?></h2>
<?php echo $session->flash()?>

<div class="buttons atbottom">
	<ul>
		<li><a href="javascript:void(0)" class="cancel"><?php __("Xóa")?></a></li>
	</ul>
</div>
<div class='right_table'>
<?php echo $form->create('Contact', array(
	'url'	=>	
	$params + array(
		'controller'	=>	$this->params['controller'],	
		'action'		=>	'update_priority'
	)
));?>
<div class="table">
	<table cellpadding="0" cellspacing="0" id='news_list'>
		<thead>
			<tr>
				<th width='20'><a><?php echo __("#"); ?></a></th>
				<th width='20'><input type="checkbox" id='checkbox-control' control='index'/></th>
				<th width='200'><?php echo $paginator->sort(__('Tên ', true), 'name'); ?></th>
				<th><?php echo $paginator->sort(__('Tiêu đề ', true), 'title'); ?></th>
				<th width='200'><?php echo $paginator->sort(__('Ngày', true) , 'content'); ?></th>
				<th width='80'><a><?php echo $paginator->sort(__('Đã đọc?', true) , 'status')?></a></th>
				<th><a><?php echo __('Chức năng'); ?></a></th>
			</tr>
		</thead>
		<tbody>
			<?php if(!$contacts):?>
			<tr class="row1">
				<td colspan="7" align="center" style="font-weight:bold"><?php echo __("Chưa có dữ liệu.");?></td>
			</tr>
			<?php
			endif;
				$max = $paginator->params['paging']['Contact']['defaults']['limit'];
				$page = $paginator->params['paging']['Contact']['page'];
				$start = ($page - 1) * $max;
				$i=0;
				$class = 'altrow';
				$room_type_list = array();
				
				foreach ($contacts as $contact):
					$class = $class == "" ? "class='odd'" : "";
					$page_id = $contact['Contact']['id'];
					$bold = $contact['Contact']['status'] == 1 ? "" : "bold";
					$class .= " {$bold}";
					$i++;
			?>
			<tr <?php echo $class?> page_id="<?php echo $page_id?>">
				<td class="center"><?php echo ($start + $i)?></td>
				<td class="center"><input type="checkbox" class='index' name='checkbox_index[]' value='<?php echo $page_id?>'/></td>
				<td>
					<?php echo $contact['Contact']['name']; ?>
					<br/><span><?php echo $contact['Contact']['email']?></span>
				</td>
				<td><?php echo $contact['Contact']['title']; ?></td>
				<td width='80' align="center"><?php echo date("d-m-Y H:i:s", strtotime($contact['Contact']['created'])); ?></td>
				<td align="center">
					<?php 
						if($contact['Contact']['status'] == 0) {
							echo __('No');
						} else {
							echo __('Yes');
						}
					?>
				</td>
				<td class='actions'>
					<div class="functions">
						<div class="header"><h4><?php __("Chức năng");?></h4></div>
						<ul>
							<li><a page_id="<?php echo $contact['Contact']['id']?>" href="<?php echo $html->url($params + array('controller'=>$this->params['controller'], 'action'=>'view', $contact['Contact']['id']))?>" class="edit view_page_link"><?php __("Xem")?></a></li>
							<li><a href="<?php echo $html->url($params + array('controller'=>$this->params['controller'], 'action'=>'delete', $contact['Contact']['id']))?>" class="delete delete_page" onclick="return confirm('<?php __("Bạn có thật sự muốn xóa thông tin này?")?>')"><?php __("Xóa")?></a></li>
						</ul>
					</div>
				</td>
			</tr>
			<?php endforeach;?>
		</tbody>
	</table>
</div>
<!-- table.end -->
<?php echo $form->end();?>
</div>
<div class="paging-wrapper">
<?php echo $this->element('pagination/pagination', array('model' => 'Contact'));?>
</div>

<div class="buttons atbottom">
	<ul>
		<li><a href="javascript:void(0)" class="cancel"><?php __("Xóa")?></a></li>
	</ul>
</div>

<?php //echo $this->element('sql_dump')?>

<div id="layer1">
	<div id="layer1_handle">
		<a href="#" id="close">[ x ]</a>
		<?php echo __('Reply This Contact', true) ?>
	</div>
	<div id="layer1_content" class="index">	
		<?php echo $form->create('Contact', array('url' => array(
			'plugin'		=> 'contacts',
			'controller'	=> 'manage_contacts',
			'action' => 'sendNewUserMail'
		)))?>
			<table>
				<tr>
					<td><?php __("Gửi đến")?></td>
					<td ><b><span><label id="id_mailTo"></label></span></b></td>
					
				</tr>
				<tr>
					<td><?php __('Title')?></td>
					<td><?php echo $form->input('title', array('label' => false, 'id' => 'contact_title')) ?></td>
				</tr>
				<tr>
					<td><?php __('Content')?></td>
					<td><?php echo $form->input('content', array('label' => false, true)); ?></td>
				</tr>
				<tr>
					<td><?php echo __('Send me this message', true);?></td>
					<td><?php echo $form->checkbox('send_me', array('multiple' => 'checkbox')) ?></td>
				</tr>
			
			</table>
			<?php echo $form->input('email',array('label' => false, 'type'=>'hidden', 'id'=>'contact_mail', 'value' => '')); ?>
			<?php echo $form->submit(__('Send', true)) ?>
		<?php echo $form->end() ?>
	</div>
</div>


<!-- Dialog -->
<div id='dialogs'>
<div id="contact_info" title="<?php __("Thông tin liên hệ ")?>"></div>
</div>
<!-- Dialog -->
<!-- Form cho sự kiện xóa -->
<form style="display:none" id='mass_delete' method='post' 
action="<?php echo $html->url(array('plugin' => 'contacts', 'controller' => 'manage_contacts', 'action' => 'mass_delete') + $params)?>"
></form>